﻿<EditForm Model="@TestModel" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
    <DataAnnotationsValidator />

    <BitTextField MaxLength="MaxLength"
                  Multiline="Multiline"
                  Type="Type"
                  Placeholder="@Placeholder"
                  ReadOnly="ReadOnly"
                  Required="Required"
                  IsEnabled="IsEnabled"
                  IconName="@IconName"
                  @bind-Value="@TestModel.Value"
                  CanRevealPassword="CanRevealPassword"
                  RevealPasswordAriaLabel="@RevealPasswordAriaLabel"
                  OnClick="HandleClick"
                  OnChange="HandleChange"
                  OnFocus="HandleFocus"
                  OnFocusIn="HandleFocusIn"
                  OnFocusOut="HandleFocusOut"
                  OnKeyDown="HandleKeyDown"
                  OnKeyUp="HandleKeyUp"
                  AriaLabel="@AriaLabel"
                  Label="@Label"
                  Underlined="Underlined"
                  NoBorder="NoBorder"
                  DefaultValue="@DefaultValue"
                  Description="@Description"
                  Prefix="@Prefix"
                  Suffix="@Suffix"
                  Rows="Rows"
                  Resizable="Resizable"
                  AutoComplete="@AutoComplete">
    </BitTextField>

</EditForm>

@code {
    [Parameter] public int MaxLength { get; set; } = -1;
    [Parameter] public string? IconName { get; set; }
    [Parameter] public bool Multiline { get; set; }
    [Parameter] public bool IsEnabled { get; set; } = true;
    [Parameter] public bool ReadOnly { get; set; }
    [Parameter] public bool Required { get; set; }
    [Parameter] public string? Placeholder { get; set; }
    [Parameter] public bool CanRevealPassword { get; set; }
    [Parameter] public string? RevealPasswordAriaLabel { get; set; }
    [Parameter] public BitInputType Type { get; set; }
    [Parameter] public string? AriaLabel { get; set; }
    [Parameter] public string? Label { get; set; }
    [Parameter] public string? Prefix { get; set; }
    [Parameter] public string? Suffix { get; set; }
    [Parameter] public string? DefaultValue { get; set; }
    [Parameter] public string? Description { get; set; }
    [Parameter] public string? ErrorMessage { get; set; }
    [Parameter] public bool Underlined { get; set; }
    [Parameter] public bool NoBorder { get; set; }
    [Parameter] public bool Resizable { get; set; }
    [Parameter] public int Rows { get; set; }
    [Parameter] public string? AutoComplete { get; set; }
    [Parameter] public BitTextFieldTestModel TestModel { get; set; } = new();

    public int CurrentCount { get; set; }
    public int FocusedValue { get; set; }
    public int FocusedOutValue { get; set; }
    public int FocusedInValue { get; set; }
    public string? KeyDownedValue { get; set; }
    public string? KeyUpedValue { get; set; }
    public int ValidCount { get; set; }
    public int InvalidCount { get; set; }

    public void HandleKeyDown(KeyboardEventArgs e)
    {
        KeyDownedValue = e.Key;
    }

    public void HandleKeyUp(KeyboardEventArgs e)
    {
        KeyUpedValue = e.Key;
    }

    public void HandleFocus(FocusEventArgs e)
    {
        FocusedValue++;
    }

    public void HandleFocusIn(FocusEventArgs e)
    {
        FocusedInValue++;
    }

    public void HandleFocusOut(FocusEventArgs e)
    {
        FocusedOutValue++;
    }

    public void HandleChange(string e)
    {
        CurrentCount++;
    }

    public void HandleClick(MouseEventArgs e)
    {
        CurrentCount++;
    }

    private void HandleValidSubmit()
    {
        ValidCount++;
    }

    private void HandleInvalidSubmit()
    {
        InvalidCount++;
    }
}
